package com.enniswu.weitter.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.enniswu.weitter.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class IconTextView extends LinearLayout {

    @BindView(R.id.iv_icon)
    ImageView ivIcon;
    @BindView(R.id.tv_description)
    TextView tvDescription;

    public IconTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.widget_icon_text, this, true);
        ButterKnife.bind(this, this);
        setOrientation(HORIZONTAL);
        TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.IconTextView);
        if (attributes != null) {
            ivIcon.setImageResource(attributes.getResourceId(R.styleable.IconTextView_ITV_src,
                    R.drawable.ic_close));
            tvDescription.setText(attributes.getString(R.styleable.IconTextView_ITV_text));
            tvDescription.setTextColor(attributes.getColor(R.styleable.IconTextView_ITV_textColor,
                    getResources().getColor(R.color.text)));
            attributes.recycle();
        }
    }
}
